package com.example.dubbo.balance;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Random;

/**
 * @author : Vick C
 * @version : v1.0
 * @date : 2020/6/16
 */
@Component
public class CustomLoadBalance extends RandomLoadBalance {

    @Override
    protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
        return invokers.get(new Random().nextInt(invokers.size()));
    }
}
